package top.bug.blog.controller.backend;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import top.bug.blog.annotation.Auth;
import top.bug.blog.common.Result;
import top.bug.blog.entity.dto.common.BatchRequest;
import top.bug.blog.entity.dto.common.SingleRequest;
import top.bug.blog.entity.dto.source.*;
import top.bug.blog.entity.po.Source;
import top.bug.blog.entity.po.SourceGroup;
import top.bug.blog.entity.vo.source.SourceCountVO;
import top.bug.blog.service.SourceService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author <a href="https://github.com/jiusi66">九思.</a>
 * @email 10837907@qq.com
 * @from <a href="https://www.52bug.top">递归茶馆-www.52bug.top</a>
 * @description 后台-素材模块
 */
@Api(tags = "素材管理模块")
@RestController
@RequestMapping("/sourceApi")
@Auth
public class SourceController {
    @Resource
    private SourceService sourceService;

    // region 素材相关

    @PostMapping("/getList")
    @ApiOperation("获取列表")
    public Result<Page<Source>> getList(@RequestBody SourceQueryRequest queryRequest) {
        return Result.success(sourceService.getList(queryRequest));
    }

    @GetMapping("/getSourceCount")
    @ApiOperation("获取素材数量")
    public Result<SourceCountVO> getSourceCount() {
        return Result.success(sourceService.getSourceCount());
    }

    @PostMapping("/uploadSource")
    @ApiOperation("素材文件上传")
    public Result<List<String>> uploadSource(SourceUploadRequest uploadRequest) {
        return Result.success(sourceService.uploadSource(uploadRequest));
    }

    @PostMapping("/batchDelete")
    @ApiOperation("批量删除")
    public Result<Boolean> batchDelete(@RequestBody BatchRequest batchRequest) {
        return Result.success(sourceService.batchDelete(batchRequest));
    }

    // endregion

    // region 素材分组

    @GetMapping("/getGroups")
    @ApiOperation("获取分组列表")
    public Result<List<SourceGroup>> getGroups() {
        return Result.success(sourceService.getGroups());
    }

    @PostMapping("/createGroup")
    @ApiOperation("创建分组")
    public Result<Boolean> createGroup(@RequestBody SourceGroupAddRequest addRequest) {
        return Result.success(sourceService.createGroup(addRequest));
    }

    @PostMapping("/deleteGroup")
    @ApiOperation("删除分组")
    public Result<Boolean> deleteGroup(@RequestBody SingleRequest singleRequest) {
        return Result.success(sourceService.deleteGroup(singleRequest));
    }

    @PostMapping("/updateGroup")
    @ApiOperation("更新分组")
    public Result<Boolean> updateGroup(@RequestBody SourceGroupUpdateRequest updateRequest) {
        return Result.success(sourceService.updateGroup(updateRequest));
    }

    @PostMapping("/batchMoveToGroup")
    @ApiOperation("移动分组")
    public Result<Boolean> batchMoveToGroup(@RequestBody SourceMoveRequest moveRequest) {
        return Result.success(sourceService.batchMoveToGroup(moveRequest));
    }

    // endregion

}